/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistence.facade;

import java.util.Collection;
import persistence.constant.PersistencePropertiesLoader;
import persistence.file.FileManager;

/**
 *
 * @author Ricardo
 */
public class FacadePersistence {
   private static FacadePersistence instance;
   private FileManager fileManager;
   private PersistencePropertiesLoader persistenceProperties;
   private static org.apache.log4j.Logger log = org.apache.log4j.Logger.getRootLogger();
   
   
   private FacadePersistence(){
       fileManager = new FileManager();
       persistenceProperties = new PersistencePropertiesLoader();
   }
   
   public static FacadePersistence getInstance(){
       if ( instance == null ){
           instance = new FacadePersistence();
       }
       return instance;
   }
   
   public void createOriginalFile( String data, int sequence ){
       String folder = persistenceProperties.getProperty("file.source.path");
       String fileName = sequence+".txt";
       log.info("Call writeFile");
       fileManager.writeFile(folder, fileName, data);
   }
   
   public void createCleanFile( String fileName, String data ){
       String folder = persistenceProperties.getProperty("file.clean.path");
       log.info("Call writeFile");
       fileManager.writeFile(folder, fileName, data);
   }
   
   public void createTokenizedFile( String fileName, String data ){
       String folder = persistenceProperties.getProperty("file.tokenized.path");
       log.info("Call writeFile");
       fileManager.writeFile(folder, fileName, data);
   }
   
   public void createSentencesFile( String fileName, String data ){
       String folder = persistenceProperties.getProperty("file.sentences.path");
       log.info("Call writeFile");
       fileManager.writeFile(folder, fileName, data);
   }
   
   
   public Collection<String> listOriginalFiles(){
       String folder = persistenceProperties.getProperty("file.source.path");
       Collection<String> listFiles = fileManager.getFileList(folder);
       return listFiles;
   }
   
   public Collection<String> listCleanFiles(){
       String folder = persistenceProperties.getProperty("file.clean.path");
       Collection<String> listFiles = fileManager.getFileList(folder);
       return listFiles;
   }
   
   public Collection<String> listTokenizedFiles(){
       String folder = persistenceProperties.getProperty("file.tokenized.path");
       Collection<String> listFiles = fileManager.getFileList(folder);
       return listFiles;
   }
   
    public Collection<String> listSentencesFiles() {
        String folder = persistenceProperties.getProperty("file.sentences.path");
        Collection<String> listFiles = fileManager.getFileList(folder);
        return listFiles;
    }
   
   public String getFileData( String fileName ){
       return this.fileManager.readFile(fileName);
   }
   
   public String getFileName( String path ){
       return this.fileManager.getFileName(path);
   }
   
   
}
